package com.woniuxy.yoga.course.service.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.woniuxy.yoga.coach.dao.model.Coach;
import com.woniuxy.yoga.commons.core.model.PageInfo;
import com.woniuxy.yoga.commons.core.model.Result;
import com.woniuxy.yoga.commons.core.statedata.BusinessState;
import com.woniuxy.yoga.commons.core.statedata.CoachState;
import com.woniuxy.yoga.commons.core.statedata.CourseState;
import com.woniuxy.yoga.commons.core.statedata.UserState;
import com.woniuxy.yoga.commons.core.util.DateUtil;
import com.woniuxy.yoga.course.client.*;
import com.woniuxy.yoga.course.client.dto.business.BusinessStoreDTO;
import com.woniuxy.yoga.course.client.dto.business.StoreClassroomByIdDTO;
import com.woniuxy.yoga.course.client.dto.course.CourseTypeDTO;
import com.woniuxy.yoga.course.client.dto.user.UserInfoDTO;
import com.woniuxy.yoga.course.client.form.GetUnfinishPriByIdForm;
import com.woniuxy.yoga.course.dao.model.AloneCourse;
import com.woniuxy.yoga.course.dao.mapper.AloneCourseMapper;
import com.woniuxy.yoga.course.model.dto.alone.AllAloneCourseDTO;
import com.woniuxy.yoga.course.model.dto.alone.AloneCourseDTO;
import com.woniuxy.yoga.course.model.dto.alone.AloneReservationDTO;
import com.woniuxy.yoga.course.model.dto.alone.CoachAloneCourseDTO;
import com.woniuxy.yoga.course.model.dto.ordinary.OrdinaryCourseDTO;
import com.woniuxy.yoga.course.model.dto.team.TeamCourseDTO;
import com.woniuxy.yoga.course.model.exception.CourseException;
import com.woniuxy.yoga.course.model.exception.CourseExceptionCode;
import com.woniuxy.yoga.course.model.param.alone.AddAloneCourseParam;
import com.woniuxy.yoga.course.model.param.alone.AmountAloneCourseDurationParam;
import com.woniuxy.yoga.course.model.param.alone.CoachQueryAloneCourseParam;
import com.woniuxy.yoga.course.model.param.alone.QueryAllAloneCourseParam;
import com.woniuxy.yoga.course.service.service.AloneCourseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * <p>
 * 私教课程表 服务实现类
 * </p>
 *
 * @author 韦用文,刘存益,郎腾霄
 * @since 2023年11月28日
 */
@Service
public class AloneCourseServiceImpl extends ServiceImpl<AloneCourseMapper, AloneCourse> implements AloneCourseService {

    @Autowired
    private AloneCourseMapper aloneCourseMapper;

    @Autowired
    private CourseClient courseClient;

    @Autowired
    private CoachClient coachClient;

    @Autowired
    private UserClient userClient;

    @Autowired
    private BusinessClient businessClient;

    @Autowired
    private ProgressClient progressClient;

    /**
     * 教练ID查询私教课程
     * @param ids
     * @return
     */
    @Override
    public List<AloneCourseDTO> getByCoachId(List<Integer> ids) {
        QueryWrapper<AloneCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("coach_id",ids.get(0));
        //索引排序
        wrapper.orderByAsc("course_id");
        List<AloneCourse> aloneCourses = aloneCourseMapper.selectList(wrapper);
        //集合转换
        List<AloneCourseDTO> aloneCourseDTOS = BeanUtil.copyToList(aloneCourses, AloneCourseDTO.class);
        return aloneCourseDTOS;
    }

    /**
     * 统计该时间段私教课程已完成的总时长
     * @param param
     * @return
     */
    @Override
    public Integer amountAloneCourseDuration(AmountAloneCourseDurationParam param) {
        QueryWrapper<AloneCourse> wrapper = new QueryWrapper<>();
        wrapper.ge("course_start_time",param.getStartTime());
        wrapper.le("course_end_time",param.getEndTime());
        wrapper.eq("store_id",param.getStoreId());
        wrapper.eq("course_state", CourseState.ALONE_COURSE_STATE_DONE);
        //查询数据
        List<AloneCourse> aloneCourses = aloneCourseMapper.selectList(wrapper);
        //准备一个参数用于记录私教总时长
        Integer duration = 0;
        //判断是否存在
        if (aloneCourses!=null&&aloneCourses.size()>0){
            //遍历获取时长
            for (AloneCourse aloneCours : aloneCourses) {
                duration += aloneCours.getCourseDuration();
            }
        }
        return duration;
    }

    /**
     * 新增私教课程
     * @param param
     */
    @Override
    @GlobalTransactional(rollbackFor = Exception.class)
    public void addAloneCourse(AddAloneCourseParam param) {
        //判断私教预约是否报错
        Result<AloneReservationDTO> aloneReservationDTOResult = courseClient.getAloneReservationById(param.getReservationId());
        if (aloneReservationDTOResult.getCode()!=200) throw new CourseException(aloneReservationDTOResult.getCode(),aloneReservationDTOResult.getMessage());
        //获取数据
        AloneReservationDTO aloneReservationDTO = aloneReservationDTOResult.getData();
        //判断是否存在
        if (aloneReservationDTO==null) throw new CourseException(CourseExceptionCode.COURSE_EXCEPTION_CODE_ALONE_RESERVATION_NOT_EXIST);
        //判断私教预约状态是否已确认
        if (aloneReservationDTO.getReservationState()!=CourseState.RESERVATION_STATE_CONFIRMED) throw new CourseException(CourseExceptionCode.COURSE_EXCEPTION_CODE_ALONE_RESERVATION_STATE_ERROR);
        //获取开始时间
        String courseStartTime = param.getCourseStartTime();
        long startTime = DateUtil.convertToMilliseconds(courseStartTime);
        //获取结束时间
        String courseEndTime = param.getCourseEndTime();
        long endTime = DateUtil.convertToMilliseconds(courseEndTime);
        //判断开始时间是否大于等于结束时间
        if (startTime>=endTime) throw new CourseException(CourseExceptionCode.COURSE_EXCEPTION_CODE_ALONE_RESERVATION_TIME_ERROR);
        //获取当前时间
        long time = new Date().getTime();
        //判断开始时间是否是未来时间
        if (startTime<=time) throw new CourseException(CourseExceptionCode.COURSE_EXCEPTION_CODE_ALONE_RESERVATION_TIME_ERROR);
        //将教练ID保存到集合中
        List<Integer> ids = new ArrayList<>();
        ids.add(aloneReservationDTO.getCoachId());
        //获取该教练的所有待开课或已开课的普通课程 判断排课时间是否冲突
        Result<List<OrdinaryCourseDTO>> ordinaryCourseDTOResult = courseClient.getOrdinaryByCoachId(ids);
        if (ordinaryCourseDTOResult.getCode()!=200) throw new CourseException(ordinaryCourseDTOResult.getCode(),ordinaryCourseDTOResult.getMessage());
        //获取数据
        List<OrdinaryCourseDTO> ordinaryCourseDTOS = ordinaryCourseDTOResult.getData();
        //判断是否存在该教练的普通课程
        if (ordinaryCourseDTOS!=null&&ordinaryCourseDTOS.size()>0){
            //遍历该教练的所有普通课程
            for (OrdinaryCourseDTO ordinaryCourseDTO : ordinaryCourseDTOS) {
                //判断课程状态是否是待开课或者已开课
                if (ordinaryCourseDTO.getCourseState()==CourseState.ORDINARY_COURSE_STATE_WAIT || ordinaryCourseDTO.getCourseState()==CourseState.ORDINARY_COURSE_STATE_START){
                    //获取课程的开课时间
                    String courseStartDate = ordinaryCourseDTO.getCourseStartDate();
                    long startDate = DateUtil.convertToMilliseconds(courseStartDate);
                    //获取课程的结课时间
                    String courseEndDate = ordinaryCourseDTO.getCourseEndDate();
                    long endDate = DateUtil.convertToMilliseconds(courseEndDate);
                    //判断新增的私教课程时间是否存在教练时间冲突
                    if (!((startDate<startTime&&endDate<startTime) || (startDate>endTime&&endDate>endTime))){
                        //存在 教练时间冲突
                        throw new CourseException(CourseExceptionCode.COURSE_EXCEPTION_CODE_COACH_TIME_CONFLICT);
                    }
                }
            }
        }
        //获取该教练的所有待开课或已开课的团队课程 判断排课时间是否冲突
        Result<List<TeamCourseDTO>> teamCourseDTOResult = courseClient.getTeamCourseByCoachId(ids);
        if (teamCourseDTOResult.getCode()!=200) throw new CourseException(teamCourseDTOResult.getCode(),teamCourseDTOResult.getMessage());
        //获取数据
        List<TeamCourseDTO> teamCourseDTOS = teamCourseDTOResult.getData();
        //判断是否存在
        if (teamCourseDTOS!=null&&teamCourseDTOS.size()>0){
            //遍历该教练的所有团队课程
            for (TeamCourseDTO teamCourseDTO : teamCourseDTOS) {
                //判断课程状态是否是待开课或者是进行中
                if (teamCourseDTO.getTeamCourseState()==CourseState.TEAM_COURSE_STATE_WAIT || teamCourseDTO.getTeamCourseState()==CourseState.TEAM_COURSE_STATE_HAVE){
                    //获取团课开课时间
                    String teamStartTime = teamCourseDTO.getStartTime();
                    long teamStartDate = DateUtil.convertToMilliseconds(teamStartTime);
                    //获取团课结束时间
                    String teamEndTime = teamCourseDTO.getEndTime();
                    long teamEndDate = DateUtil.convertToMilliseconds(teamEndTime);
                    //判断新增团队课程的教室时间是否存在冲突
                    if (!((teamStartDate<startTime&&teamEndDate<startTime) || (teamStartDate>endTime&&teamEndDate>endTime))){
                        //存在 教练时间冲突
                        throw new CourseException(CourseExceptionCode.COURSE_EXCEPTION_CODE_COACH_TIME_CONFLICT);
                    }
                }
            }
        }
        //获取两个时间之间的时长 判断时长是否足够
        long courseTime = endTime - startTime;
        int duration = (int)(courseTime/(1000*60*60));
        if (duration<2) throw new CourseException(CourseExceptionCode.COURSE_EXCEPTION_CODE_COURSE_TIME_DELETION);
        //判断教室是否为空
        if (ObjectUtil.isNotEmpty(param.getClassroomId())){
            //判断教室是否报错
            Result<StoreClassroomByIdDTO> storeClassroomByIdDTOResult = businessClient.selNormalByStoreClassroomId(param.getClassroomId());
            if(storeClassroomByIdDTOResult.getCode()!=200) throw new CourseException(storeClassroomByIdDTOResult.getCode(),storeClassroomByIdDTOResult.getMessage());
            //获取数据
            StoreClassroomByIdDTO storeClassroomByIdDTO = storeClassroomByIdDTOResult.getData();
            //判断是否存在
            if (storeClassroomByIdDTO==null) throw new CourseException(CourseExceptionCode.COURSE_EXCEPTION_CODE_CLASS_ROOM_NOT_EXIST);
            //判断教室状态是否异常
            if (storeClassroomByIdDTO.getClassroomState()!=BusinessState.CLASSROOM_STATE_NORMAL) throw new CourseException(CourseExceptionCode.COURSE_EXCEPTION_CODE_CLASS_ROOM_STATE_ERROR);
            //判断教室是否是普通教室
            if (storeClassroomByIdDTO.getClassroomType()==1) throw new CourseException(CourseExceptionCode.COURSE_EXCEPTION_CODE_CLASS_ROOM_IS_TEAM_CLASS_ROOM);
            //判断该时间段的普通课程教室是否冲突
            Result<List<OrdinaryCourseDTO>> ordinaryCourseDTOsResult = courseClient.getOrdinaryCourseByClassroomId(param.getClassroomId());
            if (ordinaryCourseDTOsResult.getCode()!=200) throw new CourseException(ordinaryCourseDTOsResult.getCode(),ordinaryCourseDTOsResult.getMessage());
            //获取数据
            List<OrdinaryCourseDTO> ordinaryCourseDTO = ordinaryCourseDTOsResult.getData();
            //判断是否存在数据
            if (ordinaryCourseDTO!=null&&ordinaryCourseDTO.size()>0){
                //遍历该教室的所有普通课程
                for (OrdinaryCourseDTO courseDTO : ordinaryCourseDTO) {
                    //筛选出待开课和已开课的普通课程
                    if (courseDTO.getCourseState()==CourseState.ORDINARY_COURSE_STATE_WAIT || courseDTO.getCourseState()==CourseState.ORDINARY_COURSE_STATE_START){
                        //获取普通课程开课时间
                        String courseStartDate = courseDTO.getCourseStartDate();
                        long startDate = DateUtil.convertToMilliseconds(courseStartDate);
                        //获取普通课程结束时间
                        String courseEndDate = courseDTO.getCourseEndDate();
                        long endDate = DateUtil.convertToMilliseconds(courseEndDate);
                        //判断新增的预约课程教室时间是否存在冲突
                        if (((startDate<startTime&&endDate<startTime) || (startDate>endTime&&endDate>endTime))){
                            //存在 教室冲突
                            throw new CourseException(CourseExceptionCode.COURSE_EXCEPTION_CODE_CLASS_ROOM_TIME_CONFLICT);
                        }
                    }
                }
            }
        }
        //对象转换
        AloneCourse aloneCourse = BeanUtil.toBean(param, AloneCourse.class);
        //课程时长赋值
        aloneCourse.setCourseDuration(duration);
        //课程类型赋值
        aloneCourse.setCourseTypeId(2);
        //教练ID赋值
        aloneCourse.setCoachId(aloneReservationDTO.getCoachId());
        //门店ID赋值
        aloneCourse.setStoreId(aloneReservationDTO.getStoreId());
        //用户ID赋值
        aloneCourse.setUserId(aloneReservationDTO.getUserId());
        //用户名称赋值
        aloneCourse.setUserName(aloneReservationDTO.getUserName());
        //状态赋值
        aloneCourse.setCourseState(CourseState.ALONE_COURSE_STATE_ING);
        //新增数据
        aloneCourseMapper.insert(aloneCourse);
        //私教课程新增成功 私教预约课程次数减一
        Result<?> result = courseClient.reduceAloneReservationCount(param.getReservationId());
        if (result.getCode()!=200) throw new CourseException(result.getCode(),result.getMessage());
        //获取私教进度卡ID
        GetUnfinishPriByIdForm getUnfinishPriByIdForm = new GetUnfinishPriByIdForm();
        getUnfinishPriByIdForm.setCoachId(aloneReservationDTO.getCoachId());
        getUnfinishPriByIdForm.setUserId(aloneReservationDTO.getUserId());
        Result<Integer> integerResult = progressClient.getUnfinishPriById(getUnfinishPriByIdForm);
        if (integerResult.getCode()!=200) throw new CourseException(integerResult.getCode(),integerResult.getMessage());
        Integer pricardId = integerResult.getData();
        if (pricardId==null) throw new CourseException(CourseExceptionCode.COURSE_EXCEPTION_CODE_PRIVATE_NOT_EXIST);
        //私教进度加一
        Result<String> stringResult = progressClient.addPriCardCount(pricardId);
        if (stringResult.getCode()!=200) throw new CourseException(stringResult.getCode(),stringResult.getMessage());
    }

    /**
     * 修改成已完成
     * @param courseId
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void modifyAloneCourseComplete(Integer courseId) {
        AloneCourse aloneCourse = aloneCourseMapper.selectById(courseId);
        //判断是否存在
        if (aloneCourse==null) throw new CourseException(CourseExceptionCode.COURSE_EXCEPTION_CODE_ALONE_COURSE_NOT_EXIST);
        //判断私教课程状态是否是进行中
        if (aloneCourse.getCourseState()!=CourseState.ALONE_COURSE_STATE_ING) throw new CourseException(CourseExceptionCode.COURSE_EXCEPTION_CODE_ALONE_COURSE_STATE_ERROR);
        //获取结课时间
        String courseEndTime = aloneCourse.getCourseEndTime();
        long endTime = DateUtil.convertToMilliseconds(courseEndTime);
        //获取当前时间
        long currentTime = new Date().getTime();
        //判断修改时间是否是结课时间之后
        if (currentTime<endTime) throw new CourseException(CourseExceptionCode.COURSE_EXCEPTION_CODE_CURRENT_TIME_NOT_ENDING);
        //修改成已完成
        aloneCourse.setCourseState(CourseState.ALONE_COURSE_STATE_DONE);
        aloneCourseMapper.updateById(aloneCourse);
    }

    /**
     * 教练查询自己的私教课程
     * @param param
     * @return
     */
    @Override
    public PageInfo coachQueryAloneCourse(CoachQueryAloneCourseParam param) {
        QueryWrapper<AloneCourse> wrapper = new QueryWrapper<>();
        wrapper.eq("coach_id",param.getCoachId());
        //类型ID搜索
        if (ObjectUtil.isNotEmpty(param.getCourseTypeId())){
            wrapper.eq("course_type_id",param.getCourseTypeId());
        }
        //私教课程开始时间搜索
        if (ObjectUtil.isNotEmpty(param.getCourseStartTime())){
            wrapper.eq("course_start_time",param.getCourseStartTime());
        }
        //私教课程结束时间搜索
        if (ObjectUtil.isNotEmpty(param.getCourseEndTime())){
            wrapper.eq("course_end_time",param.getCourseEndTime());
        }
        //用户名搜索
        if (ObjectUtil.isNotEmpty(param.getUserName())){
            wrapper.like("user_name",param.getUserName());
        }
        //索引搜索
        wrapper.orderByAsc("course_id");
        //分页查询
        Page<AloneCourse> page = new Page<>(param.getPageNum() == null ? 1 : param.getPageNum(), param.getPageSize() == null ? 10 : param.getPageSize());
        aloneCourseMapper.selectPage(page,wrapper);
        //集合转换
        List<CoachAloneCourseDTO> coachAloneCourseDTOS = new ArrayList<>();
        if (page.getRecords()!=null&&page.getRecords().size()>0){
            for (AloneCourse aloneCourse : page.getRecords()) {
                //对象转换
                CoachAloneCourseDTO coachAloneCourseDTO = BeanUtil.toBean(aloneCourse, CoachAloneCourseDTO.class);
                //课程类型名称赋值
                Result<CourseTypeDTO> courseTypeDTOResult = courseClient.getCourseTypeById(aloneCourse.getCourseTypeId());
                if (courseTypeDTOResult.getCode()!=200) throw new CourseException(courseTypeDTOResult.getCode(),courseTypeDTOResult.getMessage());
                //获取数据
                CourseTypeDTO courseTypeDTO = courseTypeDTOResult.getData();
                //判断是否存在
                if (courseTypeDTO==null) throw new CourseException(CourseExceptionCode.COURSE_EXCEPTION_CODE_COURSE_TYPE_NOT_EXIST);
                coachAloneCourseDTO.setCourseTypeName(courseTypeDTO.getCourseTypeName());
                //教练名称赋值
                Result<Coach> coachResult = coachClient.getCoachById(aloneCourse.getCoachId());
                if (coachResult.getCode()!=200) throw new CourseException(coachResult.getCode(),coachResult.getMessage());
                //获取数据
                Coach coach = coachResult.getData();
                //判断是否存在
                if (coach==null) throw new CourseException(CourseExceptionCode.COURSE_EXCEPTION_CODE_COACH_NOT_EXIST);
                coachAloneCourseDTO.setCoachName(coach.getCoachName());
                //场馆名称赋值
                Result<BusinessStoreDTO> businessStoreDTOResult = businessClient.selByBusinessStoreId(aloneCourse.getStoreId());
                if (businessStoreDTOResult.getCode()!=200) throw new CourseException(businessStoreDTOResult.getCode(),businessStoreDTOResult.getMessage());
                //获取数据
                BusinessStoreDTO businessStoreDTO = businessStoreDTOResult.getData();
                coachAloneCourseDTO.setStoreName(businessStoreDTO.getStoreName());
                //教室名称赋值
                Result<StoreClassroomByIdDTO> storeClassroomByIdDTOResult = businessClient.selNormalByStoreClassroomId(aloneCourse.getClassroomId());
                if (storeClassroomByIdDTOResult.getCode()!=200) throw new CourseException(storeClassroomByIdDTOResult.getCode(),storeClassroomByIdDTOResult.getMessage());
                //获取数据
                StoreClassroomByIdDTO storeClassroomByIdDTO = storeClassroomByIdDTOResult.getData();
                //判断是否存在
                if (storeClassroomByIdDTO==null) throw new CourseException(CourseExceptionCode.COURSE_EXCEPTION_CODE_CLASS_ROOM_NOT_EXIST);
                coachAloneCourseDTO.setClassroomName(storeClassroomByIdDTO.getClassroomName());
                //状态赋值
                coachAloneCourseDTO.setCourseState(aloneCourse.getCourseState()==0?"进行中":"已完成");
                //保存到集合中
                coachAloneCourseDTOS.add(coachAloneCourseDTO);
            }
        }
        //分页对象转换
        PageInfo pageInfo = BeanUtil.toBean(page, PageInfo.class);
        pageInfo.setPages(page.getPages());
        pageInfo.setRecords(coachAloneCourseDTOS);
        return pageInfo;
    }

    /**
     * 商家查询自己的私教课程
     * @param param
     * @return
     */
    @Override
    public PageInfo queryAllAloneCourse(QueryAllAloneCourseParam param) {
        QueryWrapper<AloneCourse> wrapper = new QueryWrapper<>();
        //类型ID搜索
        if (ObjectUtil.isNotEmpty(param.getCourseTypeId())){
            wrapper.eq("course_type_id",param.getCourseTypeId());
        }
        //私教课程开始时间搜索
        if (ObjectUtil.isNotEmpty(param.getCourseStartTime())){
            wrapper.eq("course_start_time",param.getCourseStartTime());
        }
        //私教课程结束时间搜索
        if (ObjectUtil.isNotEmpty(param.getCourseEndTime())){
            wrapper.eq("course_end_time",param.getCourseEndTime());
        }
        //用户名搜索
        if (ObjectUtil.isNotEmpty(param.getUserName())){
            wrapper.like("user_name",param.getUserName());
        }
        //状态搜索
        if (ObjectUtil.isNotEmpty(param.getCourseState())){
            wrapper.eq("course_state",param.getCourseState());
        }
        //绑定门店
        wrapper.eq("store_id",param.getStoreId());
        //索引搜索
        wrapper.orderByAsc("course_id");
        //分页查询
        Page<AloneCourse> page = new Page<>(param.getPageNum() == null ? 1 : param.getPageNum(), param.getPageSize() == null ? 10 : param.getPageSize());
        aloneCourseMapper.selectPage(page,wrapper);
        //集合数据转换
        List<AllAloneCourseDTO> allAloneCourseDTOS = new ArrayList<>();
        if (page.getRecords()!=null&&page.getRecords().size()>0){
            for (AloneCourse aloneCourse : page.getRecords()) {
                //对象转换
                AllAloneCourseDTO allAloneCourseDTO = BeanUtil.toBean(aloneCourse, AllAloneCourseDTO.class);
                //课程类型名称赋值
                Result<CourseTypeDTO> courseTypeDTOResult = courseClient.getCourseTypeById(aloneCourse.getCourseTypeId());
                if (courseTypeDTOResult.getCode()!=200) throw new CourseException(courseTypeDTOResult.getCode(),courseTypeDTOResult.getMessage());
                //获取数据
                CourseTypeDTO courseTypeDTO = courseTypeDTOResult.getData();
                //判断是否存在
                if (courseTypeDTO==null) throw new CourseException(CourseExceptionCode.COURSE_EXCEPTION_CODE_COURSE_TYPE_NOT_EXIST);
                allAloneCourseDTO.setCourseTypeName(courseTypeDTO.getCourseTypeName());
                //教练名称赋值
                Result<Coach> coachResult = coachClient.getCoachById(aloneCourse.getCoachId());
                if (coachResult.getCode()!=200) throw new CourseException(coachResult.getCode(),coachResult.getMessage());
                //获取数据
                Coach coach = coachResult.getData();
                //判断是否存在
                if (coach==null) throw new CourseException(CourseExceptionCode.COURSE_EXCEPTION_CODE_COACH_NOT_EXIST);
                allAloneCourseDTO.setCoachName(coach.getCoachName());
                //场馆名称赋值
                Result<BusinessStoreDTO> businessStoreDTOResult = businessClient.selByBusinessStoreId(aloneCourse.getStoreId());
                if (businessStoreDTOResult.getCode()!=200) throw new CourseException(businessStoreDTOResult.getCode(),businessStoreDTOResult.getMessage());
                //获取数据
                BusinessStoreDTO businessStoreDTO = businessStoreDTOResult.getData();
                allAloneCourseDTO.setStoreName(businessStoreDTO.getStoreName());
                //教室名称赋值
                Result<StoreClassroomByIdDTO> storeClassroomByIdDTOResult = businessClient.selNormalByStoreClassroomId(aloneCourse.getClassroomId());
                if (storeClassroomByIdDTOResult.getCode()!=200) throw new CourseException(storeClassroomByIdDTOResult.getCode(),storeClassroomByIdDTOResult.getMessage());
                //获取数据
                StoreClassroomByIdDTO storeClassroomByIdDTO = storeClassroomByIdDTOResult.getData();
                //判断是否存在
                if (storeClassroomByIdDTO==null) throw new CourseException(CourseExceptionCode.COURSE_EXCEPTION_CODE_CLASS_ROOM_NOT_EXIST);
                allAloneCourseDTO.setClassroomName(storeClassroomByIdDTO.getClassroomName());
                //状态赋值
                allAloneCourseDTO.setCourseState(aloneCourse.getCourseState()==0?"进行中":"已完成");
                //保存到集合中
                allAloneCourseDTOS.add(allAloneCourseDTO);
            }
        }
        //分页对象转换
        PageInfo pageInfo = BeanUtil.toBean(page, PageInfo.class);
        pageInfo.setPages(page.getPages());
        pageInfo.setRecords(allAloneCourseDTOS);
        return pageInfo;
    }
}
